export const getPageHeight = ({ pageType, height }) => {
  let _height = 297;
  switch (pageType) {
    case "1": // 自定义
      _height = height;
      break;
    case "A3":
      _height = 420;
      break;
    case "A4":
      _height = 297;
      break;
    case "A5":
      _height = 210;
      break;
    case "A6":
      _height = 148;
      break;
  }
  return _height;
};

export const getPageWidth = ({ pageType, width }) => {
  let _width = 297;
  switch (pageType) {
    case "1": // 自定义
      _width = width;
      break;
    case "A3":
      _width = 379;
      break;
    case "A4":
      _width = 210;
      break;
    case "A5":
      _width = 148;
      break;
    case "A6":
      _width = 105;
      break;
  }
  return _width;
};

export const romeTrans = (num) => {
  let numArr = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
  let RomaArr = [
    "M",
    "CM",
    "D",
    "CD",
    "C",
    "XC",
    "L",
    "XL",
    "X",
    "IX",
    "V",
    "IV",
    "I",
  ];
  let index = 0;
  let res = "";
  while (index < 13) {
    while (num >= numArr[index]) {
      res += RomaArr[index];
      num -= numArr[index];
    }
    index++;
  }
  return res;
};
export const chineseTrans = (num) => {
  let changeNum = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
  let unit = ["", "十", "百", "千", "万"];
  num = parseInt(num);
  let getWan = (temp) => {
    let strArr = temp
      .toString()
      .split("")
      .reverse();
    let newNum = "";
    let newArr = [];
    strArr.forEach((item, index) => {
      newArr.unshift(
        item === "0" ? changeNum[item] : changeNum[item] + unit[index]
      );
    });
    let numArr = [];
    newArr.forEach((m, n) => {
      if (m !== "零") numArr.push(n);
    });
    if (newArr.length > 1) {
      newArr.forEach((m, n) => {
        if (newArr[newArr.length - 1] === "零") {
          if (n <= numArr[numArr.length - 1]) {
            newNum += m;
          }
        } else {
          newNum += m;
        }
      });
    } else {
      newNum = newArr[0];
    }
    return newNum;
  };
  let overWan = Math.floor(num / 10000);
  let noWan = num % 10000;
  if (noWan.toString().length < 4) {
    noWan = "0" + noWan;
  }
  return overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
};


export const pageNumText =(footerStyle,pageNum,pageTotals)=>{
  switch (footerStyle) {
    case "1":
      return pageNum;
    case "2":
      return `- ${pageNum} -`;
    case "3":
      return `—— ${pageNum} ——`;
    case "4":
      return romeTrans(pageNum);
    case "5":
      return `第${pageNum}页`;
    case "6":
      return `第${pageNum}页 共${pageTotals}页`;
    case "7":
      return `${pageNum}/${pageTotals}`;
    case "8":
      return `第${chineseTrans(pageNum)}页`;
    case "9":
      return `第${chineseTrans(pageNum)}页 共${chineseTrans(
        pageTotals
      )}页`;
  }
  return pageNum;
}